package com.zaimokuza.cn.util.grace;


import com.zaimokuza.cn.entity.enums.CustomizeExceptionEnum;
import com.zaimokuza.cn.entity.response.ResponseEntity;

import java.util.Map;

/**
 * 优雅返回的统一封装
 *
 * @author zaimokuza
 */
public class GraceResponse {

    /**
     * 请求成功响应
     *
     * @return 请求响应对象
     */
    public static ResponseEntity success() {
        return new ResponseEntity(CustomizeExceptionEnum.SUCCESS);
    }

    public static ResponseEntity success(Object data) {
        ResponseEntity entity = new ResponseEntity(CustomizeExceptionEnum.SUCCESS);
        entity.setResultData(data);
        return entity;
    }

    /**
     * 请求失败响应
     *
     * @return 请求响应对象
     */
    public static ResponseEntity error() {
        return new ResponseEntity(CustomizeExceptionEnum.FAILED);
    }

    public static ResponseEntity error(CustomizeExceptionEnum customizeExceptionEnum) {
        return new ResponseEntity(customizeExceptionEnum);
    }

    public static ResponseEntity error(CustomizeExceptionEnum customizeExceptionEnum, String resultMsg) {
        return new ResponseEntity(customizeExceptionEnum, resultMsg);
    }

    public static ResponseEntity errorMap(Map map) {
        ResponseEntity entity = new ResponseEntity(CustomizeExceptionEnum.VALIDATION_FAILED);
        entity.setResultData(map);
        return entity;
    }

}
